<!--
 * @author: 十一
 * @since: 2024-10-30
 * ExamineDrawer.vue
 * @desc: new page
-->
<template>
  <a-drawer
    :title="title"
    placement="right"
    :width="width"
    v-model:visible="visible"
  >
  <h2 style="text-align: center; font-weight: bold;">双月工作考核表</h2>
        <!-- 从我的考核 - 待提交进入 可编辑 -->
        <div style="margin-bottom: 60px;" v-if="drawerRecord && source==0||source==2||source==4">
            <div style="border-top: 1px solid #f0f0f0;">
                <div class="table-header">
                    <div style="width: 100px;">姓名</div>
                    <div style="flex: 1;">{{ drawerRecord.empname }}</div>
                    <div style="flex: 1;">部门</div>
                    <div style="flex: 1;">{{ drawerRecord.orgName }}</div>
                    <div style="flex: 1;">职称</div>
                    <div style="flex: 2;">
                        <a-input type="text" placeholder="请输入职称" v-model:value="drawerRecord.jobTitle"
                            v-if="source==0" />
                        <span v-if="source==2 ||source==4">{{ drawerRecord.jobTitle }}</span>
                    </div>
                    <div style="width: 100px;">岗位</div>
                    <div style="flex: 2;">
                        <a-input type="text" placeholder="请输入岗位" v-model:value="drawerRecord.position"
                            v-if="source==0" />
                        <span v-if="source==2 ||source==4">{{ drawerRecord.position }}</span>
                    </div>
                    <div style="width: 100px;">职务</div>
                    <div style="flex: 1;">
                        <a-input type="text" placeholder="请输入职务" v-model:value="drawerRecord.duty"
                            v-if="source==0" />
                        <span v-if="source==2 ||source==4">{{ drawerRecord.duty }}</span>
                    </div>
                </div>
                <div class="table-header">
                    <div style="background: #fafafa; width: 100%;">工作总结</div>
                </div>
                <div class="table-header">
                    <div
                        style=" min-height: 240px;width: 100%;display: flex;justify-content: flex-start;align-items: flex-start">
                        <a-textarea placeholder="请输入工作总结" rows="4" style="height: 100%;resize: none;"
                            v-model:value="drawerRecord.workSummary" v-if="source==0" />
                        <span v-if="source==2 ||source==4" style="padding: 10px">{{ drawerRecord.workSummary }}</span>
                    </div>
                </div>

                <div class="table-header">
                    <div style="width: 100px">
                        备注
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;">
                        <a-input placeholder="请输入备注信息" v-model:value="drawerRecord.remarks"
                            v-if="source==0"></a-input>
                        <span v-if="source==2 ||source==4" style="padding: 0 10px">{{ drawerRecord.remarks }}</span>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;" v-if="source==0">
                      <div style="padding: 10px;">
                        <a-upload
                            v-model:fileList="firstFile"
                            name="file"
                            :multiple="true"
                            accept=".pdf"
                           :customRequest="event => uploadFile(event, '1-0')"
                        >
                            <!-- <p class="ant-upload-drag-icon">
                            <inbox-outlined></inbox-outlined>
                            </p>
                            <p class="ant-upload-text">请上传附件</p>
                            <p class="ant-upload-hint" style="padding: 0 10px;">
                                把文件拖入指定区域，完成上传，同样支持点击上传，支持多文件上传（支持的格式：pdf）
                            </p> -->
                            <a-button>
                                <upload-outlined></upload-outlined>
                                上传附件 (请上传PDF文件)
                            </a-button>
                        </a-upload>
                      </div>
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;" v-if="source==2 ||source==4">
                        <div style="padding: 10px;">
                            <a :href="item.attachmenturl" target="_blank" v-for="item in firstFile" :key="index">{{ item.name }}</a>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="background: #fafafa;width: 100%;position: relative;">
                        <div style="border: none;">工作计划</div>
                        <a-button style="position: absolute;right: 20px;" size="small" type="primary"
                            v-if="source==0" @click="handleAddWorkPlan">新增</a-button>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">序号</div>
                    <div style="flex: 4;">工作计划</div>
                    <div style="width: 140px;">拟定完成工作时间</div>
                    <div style="flex: 4;">备注</div>
                    <div style="flex: 1;" v-if="source==0">操作</div>
                </div>
                <div class="table-header" v-for="(item, index) in workPlan" :key="index">
                    <div style="width: 100px">{{ index + 1 }}</div>
                    <div style="flex: 4;">
                        <a-input placeholder="请输入工作计划" v-model:value="item.workPlanContent"
                            v-if="source==0" />
                        <span v-if="source==2 ||source==4">{{ item.workPlanContent }}</span>
                    </div>
                    <div style="width: 140px;padding: 0 10px;">
                        <a-date-picker v-model:value="item.plannedCompletionDate" v-if="source==0" />
                        <span v-if="source==2 ||source==4">{{ item.plannedCompletionDate }}</span>
                    </div>
                    <div style="flex: 4;">
                        <a-input placeholder="请输入备注" v-model:value="item.remarks" v-if="source==0" />
                        <span v-if="source==2 ||source==4">{{ item.remarks }}</span>
                    </div>
                    <div style="flex: 1;" v-if="source==0"><a-tag color="error"
                            @click="handleDelWorkPlan(index)" style="cursor: pointer;">删除</a-tag></div>
                </div>
                <div class="table-header" v-if="workPlan.length == 0">
                    <div style="width: 100%;color: #f00f00;">请添加工作计划</div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;" v-if="source==0">
                      <div style="padding: 10px;">
                        <a-upload
                            v-model:fileList="secondFile"
                            name="file"
                            :multiple="true"
                           accept=".pdf"
                           :customRequest="event => uploadFile(event, '1-1')"
                        >
                            <!-- <p class="ant-upload-drag-icon">
                            <inbox-outlined></inbox-outlined>
                            </p>
                            <p class="ant-upload-text">请上传附件</p>
                            <p class="ant-upload-hint" style="padding: 0 10px;">
                                把文件拖入指定区域，完成上传，同样支持点击上传，支持多文件上传（支持的格式：pdf）
                            </p> -->
                            <a-button>
                                <upload-outlined></upload-outlined>
                                上传附件 (请上传PDF文件)
                            </a-button>
                        </a-upload>
                      </div>
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;" v-if="source==2 ||source==4">
                        <div style="padding: 10px;">
                            <a :href="item.attachmenturl" target="_blank" v-for="item in secondFile" :key="index">{{ item.name }}</a>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="background: #fafafa;width: 100%;">工作考核自评</div>
                </div>
                <div class="table-header">
                    <div rowspan="2" style="width: 100px">考核项</div>
                    <div style="flex: 6;padding: 0 10px;">考核内容</div>
                    <div style="flex: 1;">最高得分</div>
                    <div style="flex: 1;" v-if="drawerRecord && drawerRecord.personnelType == 0">自评分</div>
                    <div style="flex: 1;" v-if="drawerRecord.personnelType == 0 || drawerRecord.personnelType == 1">部门评分
                    </div>
                    <div style="flex: 1;">支部评分</div>
                    <div style="flex: 1;">领导评分</div>
                </div>
                <div class="table-header" v-for="(item, index) in personalScoreList" :key="index"
                    style="display: flex;">
                    <div style="width: 100px;">{{ item.contentName }}</div>
                    <div style="flex: 1;display: flex;flex-direction: column;border-right: none;border-bottom: none;">
                        <div v-for="children in item.children" :key="children.id"
                            style="width: 1134px;display: flex;border-bottom: 1px solid #f0f0f0" class="table-chidren">
                            <div style="flex: 6;justify-content: flex-start;padding: 0 10px;">
                                <!-- {{ children &&children.content }} -->
                                <span v-html="children.content"></span>
                            </div>
                            <div style="flex: 1;">{{ children.maxScore }}</div>
                            <div style="flex: 1;" class="clear-border"
                                v-if="drawerRecord && drawerRecord.personnelType == 0">
                                <a-input-number style="height: 30px;" min="0" :max="children.maxScore"
                                    v-model:value="children.selfRating"
                                    v-if="drawerRecord.status == 1 || drawerRecord.status == -2 || drawerRecord.status == -3" />
                                <div v-else style="border: none;">{{ children.selfRating }}</div>
                            </div>
                            <div style="flex: 1;" class="clear-border"
                                v-if="drawerRecord.personnelType == 0 || drawerRecord.personnelType == 1">
                                <a-input-number style="height: 30px;" min="0" :max="children.maxScore"
                                    v-model:value="children.departmentRating" v-if="drawerRecord.status == 2" />
                                <div v-else style="border: none;">{{ children.departmentRating }}</div>
                            </div>
                            <div style="flex: 1;" class="clear-border">
                                <a-input-number style="height: 30px;" min="0" :max="children.maxScore"
                                    v-model:value="children.branchRating" v-if="drawerRecord.status == 101" />
                                <div v-else style="border: none;">{{ children.branchRating }}</div>
                            </div>
                            <div style="flex: 1;border-right: 1px solid #f0f0f0;" class="clear-border">
                                <a-input-number style="height: 30px;" min="0" :max="children.maxScore"
                                    v-model:value="children.supervisorRating"
                                    v-if="drawerRecord.status == 3 || drawerRecord.status == 102" />
                                <div v-else style="border: none;">{{ children.supervisorRating }}</div>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="table-header">
                    <div style="width: 100px">合并</div>
                    <div style="flex: 6;padding: 0 10px;"></div>
                    <div style="flex: 1;">总分：{{ calculationMaxScore }}</div>
                    <div style="flex: 1;" v-if="drawerRecord && drawerRecord.personnelType == 0">总分：{{
                        calculationSelfRating
                    }}</div>
                    <div style="flex: 1;" v-if="drawerRecord.personnelType == 0 || drawerRecord.personnelType == 1">
                        总分：{{
                        calculationDepartmentRating }}</div>
                    <div style="flex: 1;">总分：{{ calculationBranchRating }}</div>
                    <div style="flex: 1;">总分：{{ calculationSupervisorRating }}</div>
                </div>
                  <div class="table-header">
                    <div style="width: 100px">评定标准</div>
                    <div style="flex: 11;">
                        <div style="padding: 10px;">
                            <div style="display: flex;justify-content: space-between;margin-bottom: 10px;" v-if="drawerRecord.personnelType == 0">
                                <span>95分及以上 &nbsp;&nbsp;A1</span>
                                <span>91-94分 &nbsp;&nbsp;A2</span>
                                <span>86-90分 &nbsp;&nbsp;B1</span>
                                <span>81-85分 &nbsp;&nbsp;B2</span>
                                <span>76-80分 &nbsp;&nbsp;B3</span>
                                <span>71-75分 &nbsp;&nbsp;C1</span>
                                <span>60-70分 &nbsp;&nbsp;C2 </span>
                                <span>59分及以下 &nbsp;&nbsp;D</span>
                            </div>
                            <div style="display: flex;justify-content: space-between;margin-bottom: 10px;" v-else>
                                <span>91分及以上 &nbsp;&nbsp;A</span>
                                <span>76-90分 &nbsp;&nbsp;B</span>
                                <span>60-75分 &nbsp;&nbsp;C</span>
                                <span>59分及以下 &nbsp;&nbsp;D</span>
                            </div>
                            <div>
                                特殊奖惩按个人考核时段所获得的个人表彰加分，国家级10分、省级5分、市级3分；个人考核时段无故缺勤1次扣2分，迟到、早退1次扣1分；受上级部门通报和纪检监察部门处分的给予扣分，被上级主管部门通报批评的扣3分，受到处分的扣5分，因履职不力、失职、失责导致工作重大失误，造成重大负面影响的扣10分；涉及违法、违规和立案调查的，另行处理。
                            </div>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">奖惩分数</div>
                    <div style="flex: 1;"><a-input type="text" v-model:value="drawerRecord.rewardPunishmentScore" />
                    </div>
                    <div style="width: 100px">理由</div>
                    <div style="flex: 10;"><a-input type="text" placeholder="请输入理由"
                            v-model:value="drawerRecord.rewardPunishmentReason" /></div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;"  v-if="source==0">
                      <div style="padding: 10px;">
                        <a-upload
                            v-model:fileList="thirdFile"
                            name="file"
                            :multiple="true"
                            accept=".pdf"
                           :customRequest="event => uploadFile(event, '1-2')"
                        >
                            <!-- <p class="ant-upload-drag-icon">
                            <inbox-outlined></inbox-outlined>
                            </p>
                            <p class="ant-upload-text">请上传附件</p>
                            <p class="ant-upload-hint" style="padding: 0 10px;">
                                把文件拖入指定区域，完成上传，同样支持点击上传，支持多文件上传（支持的格式：pdf）
                            </p> -->
                            <a-button>
                                <upload-outlined></upload-outlined>
                                上传附件 (请上传PDF文件)
                            </a-button>
                        </a-upload>
                      </div>
                    </div>
                    <div style="flex:11;display: flex;justify-content: flex-start;" v-if="source==2 ||source==4">
                        <div style="padding: 10px;">
                            <a :href="item.attachmenturl" target="_blank" v-for="item in thirdFile" :key="index">{{ item.name }}</a>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">评定等级</div>
                    <div style="flex: 11;color: #f00f00;display: flex;justify-content: flex-start;padding-left: 20px;">
                        <span v-if="drawerRecord.status == 1 || drawerRecord.status == -2 || drawerRecord.status == -3">
                            <span v-if="drawerRecord.personnelType == 0">
                                <span v-if="calculationSelfRating >= 95">A1</span>
                                <span v-if="calculationSelfRating >= 91 && calculationSelfRating <= 94">A2</span>
                                <span v-if="calculationSelfRating >= 86 && calculationSelfRating <= 90">B1</span>
                                <span v-if="calculationSelfRating >= 81 && calculationSelfRating <= 85">B2</span>
                                <span v-if="calculationSelfRating >= 76 && calculationSelfRating <= 80">B3</span>
                                <span v-if="calculationSelfRating >= 71 && calculationSelfRating <= 75">C1</span>
                                <span v-if="calculationSelfRating >= 60 && calculationSelfRating <= 70">C2</span>
                                <span v-if="calculationSelfRating <= 59">D</span>
                            </span>
                            <span v-else>
                               暂无
                            </span>
                        </span>
                        <span v-if="drawerRecord.status == 2">
                            <span v-if="drawerRecord.personnelType == 0">
                                <span v-if="calculationDepartmentRating >= 95">A1</span>
                                <span v-if="calculationDepartmentRating >= 91 && calculationDepartmentRating <= 94">A2</span>
                                <span v-if="calculationDepartmentRating >= 86 && calculationDepartmentRating <= 90">B1</span>
                                <span v-if="calculationDepartmentRating >= 81 && calculationDepartmentRating <= 85">B2</span>
                                <span v-if="calculationDepartmentRating >= 76 && calculationDepartmentRating <= 80">B3</span>
                                <span v-if="calculationDepartmentRating >= 71 && calculationDepartmentRating <= 75">C1</span>
                                <span v-if="calculationDepartmentRating >= 60 && calculationDepartmentRating <= 70">C2</span>
                                <span v-if="calculationDepartmentRating <= 59">D</span>
                            </span>
                            <span v-if="drawerRecord.personnelType == 1 || drawerRecord.personnelType == 2">
                                <span v-if="calculationDepartmentRating >= 91">A</span>
                                <span v-if="calculationDepartmentRating >= 76 && calculationDepartmentRating <= 90">B</span>
                                <span v-if="calculationDepartmentRating >= 60 && calculationDepartmentRating <= 75">C</span>
                                <span v-if="calculationDepartmentRating <= 59">D</span>
                            </span>
                        </span>
                        <span v-if="drawerRecord.status == 3">
                            <span v-if="drawerRecord.personnelType == 0">
                                暂无
                            </span>
                            <span v-if="drawerRecord.personnelType == 1 || drawerRecord.personnelType == 2">
                                <span v-if="calculationSupervisorRating >= 91">A</span>
                                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 90">B</span>
                                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 75">C</span>
                                <span v-if="calculationSupervisorRating <= 59">D</span>
                            </span>
                        </span>
                        <span v-if="drawerRecord.status == 101">
                            <!-- 普通员工 -->
                            <span v-if="drawerRecord.personnelType == 0">  
                                <span v-if="calculationBranchRating >= 95">A1</span>
                                <span v-if="calculationBranchRating >= 91 && calculationBranchRating <= 94">A2</span>
                                <span v-if="calculationBranchRating >= 86 && calculationBranchRating <= 90">B1</span>
                                <span v-if="calculationBranchRating >= 81 && calculationBranchRating <= 85">B2</span>
                                <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 80">B3</span>
                                <span v-if="calculationBranchRating >= 71 && calculationBranchRating <= 75">C1</span>
                                <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 70">C2</span>
                                <span v-if="calculationBranchRating <= 59">D</span>
                            </span>
                            <span v-if="drawerRecord.personnelType == 1 || drawerRecord.personnelType == 2">
                                <span v-if="calculationBranchRating >= 91">A</span>
                                <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 90">B</span>
                                <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 75">C</span>
                                <span v-if="calculationBranchRating <= 59">D</span>
                            </span>
                        </span>
                        <span v-if="drawerRecord.status == 102">
                            <!-- 普通员工 -->
                            <span v-if="drawerRecord.personnelType == 0">  
                                <span v-if="calculationSupervisorRating >= 95">A1</span>
                                <span v-if="calculationSupervisorRating >= 91 && calculationSupervisorRating <= 94">A2</span>
                                <span v-if="calculationSupervisorRating >= 86 && calculationSupervisorRating <= 90">B1</span>
                                <span v-if="calculationSupervisorRating >= 81 && calculationSupervisorRating <= 85">B2</span>
                                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 80">B3</span>
                                <span v-if="calculationSupervisorRating >= 71 && calculationSupervisorRating <= 75">C1</span>
                                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 70">C2</span>
                                <span v-if="calculationSupervisorRating <= 59">D</span>
                            </span>
                            <span v-if="drawerRecord.personnelType == 1 || drawerRecord.personnelType == 2">
                                <span v-if="calculationSupervisorRating >= 91">A</span>
                                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 90">B</span>
                                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 75">C</span>
                                <span v-if="calculationSupervisorRating <= 59">D</span>
                            </span>
                        </span>
                    </div>
                </div>
            </div>
        </div>

        <!-- 不可编辑 -->
        <div style="margin-bottom: 60px;" v-if="drawerRecord && source==1||source==3">
            <div style="border-top: 1px solid #f0f0f0;">
                <div class="table-header">
                    <div style="width: 100px;">姓名</div>
                    <div style="flex: 1;">{{ drawerRecord.empname }}</div>
                    <div style="flex: 1;">部门</div>
                    <div style="flex: 1;">{{ drawerRecord.orgName }}</div>
                    <div style="flex: 1;">职称</div>
                    <div style="flex: 2;">
                        <span>{{ drawerRecord.jobTitle }}</span>
                    </div>
                    <div style="width: 100px;">岗位</div>
                    <div style="flex: 2;"> <span>{{ drawerRecord.position }}</span> </div>
                    <div style="width: 100px;">职务</div>
                    <div style="flex: 1;"> <span>{{ drawerRecord.duty }}</span> </div>
                </div>
                <div class="table-header"><div style="background: #fafafa; width: 100%;">工作总结</div></div>
                <div class="table-header">
                     <div style=" min-height: 240px;width: 100%;display: flex;justify-content: flex-start;align-items: flex-start">
                        <span style="padding: 10px">{{ drawerRecord.workSummary }}</span>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px"> 备注</div>
                    <div style="flex:11;display: flex;justify-content: flex-start;"><span style="padding: 0 10px">{{ drawerRecord.remarks }}</span></div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11;justify-content: flex-start;">
                        <div style="padding: 10px;display: flex;flex-direction: column;">
                           <div v-for="item in firstFile" :key="index" style="display: flex;align-items: center;"> <PaperClipOutlined style="margin-right: 10px;color: #1890ff"/><a :href="item.attachmenturl" target="_blank" >{{ item.name }}</a></div>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="background: #fafafa;width: 100%;position: relative;">
                        <div style="border: none;">工作计划</div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">序号</div>
                    <div style="flex: 4;">工作计划</div>
                    <div style="width: 140px;">拟定完成工作时间</div>
                    <div style="flex: 4;">备注</div>
                </div>
                <div class="table-header" v-for="(item, index) in workPlan" :key="index">
                    <div style="width: 100px">{{ index + 1 }}</div>
                    <div style="flex: 4;justify-content: flex-start;padding: 0 10px;">
                        <span>{{ item.workPlanContent }}</span>
                    </div>
                    <div style="width: 140px;padding: 0 10px;">

                        <span>{{ item.plannedCompletionDate }}</span>
                    </div>
                    <div style="flex: 4;justify-content: flex-start;padding: 0 10px;">

                        <span>{{ item.remarks }}</span>
                    </div>
                </div>
                <div class="table-header" v-if="workPlan.length == 0">
                    <div style="width: 100%;color: #f00f00;">请添加工作计划</div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                 
                    <div style="flex:11;justify-content: flex-start;">
                        <div style="padding: 10px;display: flex;flex-direction: column;">
                           <div v-for="item in secondFile" :key="index" style="display: flex;align-items: center;"> <PaperClipOutlined style="margin-right: 10px;color: #1890ff"/><a :href="item.attachmenturl" target="_blank" >{{ item.name }}</a></div>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="background: #fafafa;width: 100%;">工作考核自评</div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">岗位职责</div>
                    <div style="flex: 11;">
                        <a-input value="5"></a-input>
                    </div>
                </div>
                <div class="table-header">
                    <div rowspan="2" style="width: 100px">考核项</div>
                    <div style="flex: 6;padding: 0 10px;">考核内容</div>
                    <div style="flex: 1;">最高得分</div>
                    <div style="flex: 1;" v-if="drawerRecord.personnelType == 0">自评分</div>
                    <div style="flex: 1;" v-if="drawerRecord.personnelType == 0 || drawerRecord.personnelType == 1">部门评分</div>
                    <div style="flex: 1;">支部评分</div>
                    <div style="flex: 1;">领导评分</div>
                </div>
                <div class="table-header" v-for="(item, index) in personalScoreList" :key="index"
                    style="display: flex;">
                    <div style="width: 100px;">{{ item.contentName }}</div>
                    <div style="flex: 1;display: flex;flex-direction: column;border-right: none;border-bottom: none;">
                        <div v-for="children in item.children" :key="children.id"
                            style="width: 1134px;display: flex;border-bottom: 1px solid #f0f0f0" class="table-chidren">
                            <div style="flex: 6;justify-content: flex-start;padding: 0 10px;"><span v-html="children.content"></span></div>
                            <div style="flex: 1;" v-if="drawerRecord.personnelType == 0">{{ children.maxScore }}</div>
                            <div style="flex: 1;" v-if="drawerRecord.personnelType == 0 || drawerRecord.personnelType == 1" class="clear-border"><div style="border: none;">{{ children.selfRating }}</div></div>
                            <div style="flex: 1;" class="clear-border"> <div style="border: none;">{{ children.departmentRating }}</div> </div>
                            <div style="flex: 1;" class="clear-border"><div style="border: none;">{{ children.branchRating }}</div> </div>
                            <div style="flex: 1;border-right: 1px solid #f0f0f0;" class="clear-border"> <div style="border: none;">{{ children.supervisorRating }}</div></div>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">合并</div>
                    <div style="flex: 6;padding: 0 10px;"></div>
                    <div style="flex: 1;" v-if="drawerRecord && drawerRecord.personnelType == 0">总分：{{ calculationMaxScore }}</div>
                    <div style="flex: 1;" v-if="drawerRecord.personnelType == 0 || drawerRecord.personnelType == 1">总分：{{
                        calculationSelfRating
                    }}</div>
                    <div style="flex: 1;">总分：{{ calculationDepartmentRating }}</div>
                    <div style="flex: 1;">总分：{{ calculationBranchRating }}</div>
                    <div style="flex: 1;">总分：{{ calculationSupervisorRating }}</div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">奖惩分数</div>
                    <div style="flex: 1;">
                        {{ drawerRecord.rewardPunishmentScore }}
                    </div>
                    <div style="width: 100px">理由</div>
                    <div style="flex: 10;justify-content: flex-start;padding: 0 10px;">

                        {{ drawerRecord.rewardPunishmentReason }}
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">评定标准</div>
                    <div style="flex: 11;">
                        <div style="padding: 10px;">
                            <div style="display: flex;justify-content: space-between;margin-bottom: 10px;"  v-if="drawerRecord.personnelType == 0">
                                <span>95分及以上 &nbsp;&nbsp;A1</span>
                                <span>91-94分 &nbsp;&nbsp;A2</span>
                                <span>86-90分 &nbsp;&nbsp;B1</span>
                                <span>81-85分 &nbsp;&nbsp;B2</span>
                                <span>76-80分 &nbsp;&nbsp;B3</span>
                                <span>71-75分 &nbsp;&nbsp;C1</span>
                                <span>60-70分 &nbsp;&nbsp;C2 </span>
                                <span>59分及以下 &nbsp;&nbsp;D</span>
                            </div>
                            <div style="display: flex;justify-content: space-between;margin-bottom: 10px;" v-else>
                                <span>91分及以上 &nbsp;&nbsp;A</span>
                                <span>76-90分 &nbsp;&nbsp;B</span>
                                <span>60-75分 &nbsp;&nbsp;C</span>
                                <span>59分及以下 &nbsp;&nbsp;D</span>
                            </div>
                            <div>
                                特殊奖惩按个人考核时段所获得的个人表彰加分，国家级10分、省级5分、市级3分；个人考核时段无故缺勤1次扣2分，迟到、早退1次扣1分；受上级部门通报和纪检监察部门处分的给予扣分，被上级主管部门通报批评的扣3分，受到处分的扣5分，因履职不力、失职、失责导致工作重大失误，造成重大负面影响的扣10分；涉及违法、违规和立案调查的，另行处理。
                            </div>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11;justify-content: flex-start;">
                        <div style="padding: 10px;display: flex;flex-direction: column;">
                           <div v-for="item in thirdFile" :key="index" style="display: flex;align-items: center;"> <PaperClipOutlined style="margin-right: 10px;color: #1890ff"/><a :href="item.attachmenturl" target="_blank" >{{ item.name }}</a></div>
                        </div>
                    </div>
                </div>
                <div class="table-header">
                    <div style="width: 100px">评定等级</div>
                    <div style="flex: 11;color: #f00f00;display: flex;justify-content: flex-start;padding-left: 20px;">
                        <span>{{ drawerRecord.assessmentGrade }}</span>
                    </div>
                </div>
            </div>
        </div>
        <div :style="{
            position: 'absolute',
            bottom: 0,
            width: '100%',
            borderTop: '1px solid #e8e8e8',
            padding: '10px 16px',
            textAlign: 'right',
            left: 0,
            background: '#fff',
            borderRadius: '0 0 4px 4px',
        }">
            <a-button style="margin-right: 8px" @click="() => visible = false">关闭</a-button>
            <a-button type="primary" @click="handleSaveDraft" style="margin-right: 8px" v-if="drawerRecord && source==0">保存草稿</a-button>
            <a-button type="primary" v-if="drawerRecord && source==2" danger style="margin-right: 8px" @click="()=>returnVisible = true">退回</a-button>
            <a-button type="primary" @click="handleSubmit" v-if="drawerRecord && source==0||source==2 ||source==4">提交</a-button>
        </div>
  </a-drawer>
  <a-modal v-model:visible="returnVisible" title="退回" @ok="handleOk">
        <a-textarea v-model:value="returnReason" placeholder="请输入退回原因" :rows="4" />
    </a-modal>
</template>

<script lang="ts" setup>
import { ref,computed } from 'vue'
import { GetQueryPersonalScore,GetQueryRealTimeScore,GetQueryPersonalWorkPlan,
    PostSubmitAssessmenteMoloyee,PostauditAssessment,uploadFileApi,GetFileApi} from '@/api/main'
import moment from 'moment';
import {PaperClipOutlined} from '@ant-design/icons-vue'
import { InboxOutlined } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
const visible = ref(false)  

const drawerRecord = ref()
  /**
     * status 0 全部可编辑
     * status 1 不可编辑
     * status 2 只能编辑分数
     * **/ 
const source = ref<number>(0)
const title = ref<string>('')
const width = ref(700)
// 考核内容
const personalScoreList = ref([])
// 工作计划
const workPlan = ref([])
// 显示组件
const showDrawer = (drawerOptions: any, status: boolean)=>{
    /**
     * status 0 全部可编辑
     * status 1 不可编辑
     * status 2 只能编辑分数
     * **/ 
    visible.value = true
    source.value = status
    drawerRecord.value = drawerOptions.record 
    title.value =`${ drawerOptions.title}  填报月份 : ${drawerOptions.record.reportingMonth}`
    width.value = drawerOptions.width
    if(status==0 || status==2 || status==4){
        GetQueryPersonalScoreList(drawerOptions.record)
        getWordkPlan(drawerOptions.record.id)
        getFile(drawerOptions.record.id)
    }
    if(status==1){
        GetQueryRealTimeScoreList(drawerOptions.record)
        getWordkPlan(drawerOptions.record.id)
        getFile(drawerOptions.record.id)
       
    }
    if(status==3){
        GetQueryRealTimeScoreList({id:drawerOptions.record.assessmentempId})
        getWordkPlan(drawerOptions.record.assessmentempId)
        getFile(drawerOptions.record.assessmentempId)
    }
    
}
// 获取编辑考核内容
const GetQueryPersonalScoreList = (options:any) => {
    GetQueryPersonalScore(options).then((response: any) => {
        const groupedData = {};
        // 把考核内容list 改为树形结构
        response.forEach(item => {
            if (!groupedData[item.contentType]) {
                groupedData[item.contentType] = {
                    contentType: item.contentType,
                    contentName: item.contentName,
                    children: []
                };
            }
            groupedData[item.contentType].children.push(item);
        });
        personalScoreList.value = groupedData || [];
    })
}
// 获取非编辑考核内容
const GetQueryRealTimeScoreList = (options:any) => {
    GetQueryRealTimeScore(options).then((response: any) => {
        const groupedData = {};
        // 把考核内容list 改为树形结构
        response.forEach(item => {
            if (!groupedData[item.contentType]) {
                groupedData[item.contentType] = {
                    contentType: item.contentType,
                    contentName: item.contentName,
                    children: []
                };
            }
            groupedData[item.contentType].children.push(item);
        });
        personalScoreList.value = groupedData || [];
    })
}
 const getFile = (assessmentId:any)=>{
    GetFileApi({
        khid: assessmentId
    }).then(response=>{
        response.data.forEach(item=>{
            item.uid = item.id
        })
        firstFile.value = response.data.filter(item=> item.dirPosition=='1-0')
        secondFile.value = response.data.filter(item=> item.dirPosition=='1-1')
        thirdFile.value = response.data.filter(item=> item.dirPosition=='1-2')
        console.log( firstFile.value)
        console.log( secondFile.value)
        console.log( thirdFile.value)
    })
 }
// 获取工作计划
const getWordkPlan = (assessmentId:any) => {
    GetQueryPersonalWorkPlan({
        assessmentId: assessmentId
    }).then((response => {
        workPlan.value = response.data
    }))
}
// 新增计划
const handleAddWorkPlan = () => {
    workPlan.value.push({
        glid: drawerRecord.value.id,
        workPlanContent: "",
        plannedCompletionDate: "",
        remarks: ""
    })
}
// 删除计划
const handleDelWorkPlan = (index: number) => {
    workPlan.value.splice(index, 1)
}

const firstFile = ref([]) //第1个附件
const secondFile = ref([]) //第2个附件
const thirdFile = ref([]) //第3个附件

// 上传
const  uploadFile = (info:any,status)=>{
    console.log(info.file)
    const formData = new FormData();
    formData.append("file", info.file);
    formData.append("dirPosition", status);
    formData.append("month", drawerRecord.value.reportingMonth);
    uploadFileApi(formData).then((response:any)=>{
        if(response.code==200){
            if(status=='1-0'){
                firstFile.value.forEach(item=>{
                    if(item.uid==info.file.uid){
                        item.status = 200
                        item.url = response.data.data.attachmenturl
                        item.attachmenturl = response.data.data.attachmenturl
                        item.dirPosition = response.data.data.dirPosition
                        item.id = response.data.data.id
                         }
                }) 
            }
            if(status=='1-1'){
                secondFile.value.forEach(item=>{
                    if(item.uid==info.file.uid){
                        item.status = 200
                        item.url = response.data.data.attachmenturl
                        item.attachmenturl = response.data.data.attachmenturl
                        item.dirPosition = response.data.data.dirPosition
                        item.id = response.data.data.id
                         }
                }) 
            }
            if(status=='1-2'){
                thirdFile.value.forEach(item=>{
                    if(item.uid==info.file.uid){
                        item.status = 200
                        item.url = response.data.data.attachmenturl
                        item.attachmenturl = response.data.data.attachmenturl
                        item.dirPosition = response.data.data.dirPosition
                        item.id = response.data.data.id
                         }
                }) 
            }
        }else{
            message.error(response.msg)
        }
    })
}
// 保存草稿
const handleSaveDraft = () => {
    
    workPlan.value.forEach((item:any) => {
        item.plannedCompletionDate = moment(item.plannedCompletionDate).format('YYYY-MM-DD')
    })
    const scores = [];
    for (const key in personalScoreList.value) {
        if (personalScoreList.value.hasOwnProperty(key)) {
            const children = personalScoreList.value[key].children;
            if (children && children.length > 0) {
                scores.push(...children);
            }
        }
    }
    let params = {
        employee: drawerRecord.value,
        subStatus: 0, //状态
        workPlans: workPlan.value, //计划
        scores: scores, //成绩
        qyAssessmentattachmentList:[...firstFile.value,...secondFile.value,...thirdFile.value]//附件
    }
    if( workPlan.value.length == 0){
        message.error("请添加工作计划")
        return
    }
    PostSubmitAssessmenteMoloyee(params).then((response:any) => {
        if (response.code == 200) {
            message.success(response.msg)
            visible.value = false
            emits("getData")
            visible.value = false
        } else {
            message.error(response.msg)
        }
    })
}

const emits = defineEmits(['getData'])
// 提交
const handleSubmit = () => {
    workPlan.value.some((item:any,index) => {
        item.plannedCompletionDate = moment(item.plannedCompletionDate).format('YYYY-MM-DD')
        item.planSequence = index+1
    })
    const scores = [];
    for (const key in personalScoreList.value) {
        if (personalScoreList.value.hasOwnProperty(key)) {
            const children = personalScoreList.value[key].children;
            if (children && children.length > 0) {
                scores.push(...children);
            }
        }
    }
    let params = {
        employee: drawerRecord.value,
        subStatus: 1, //状态
        workPlans: workPlan.value, //计划
        scores: scores ,//成绩
        qyAssessmentattachmentList:[...firstFile.value,...secondFile.value,...thirdFile.value]//附件
    }
    if( workPlan.value.length == 0){
        message.error("请添加工作计划")
        return
    }
    const hasNonNullPlannedCompletionDate = workPlan.value.every((item:any) => item.plannedCompletionDate!== null && item.plannedCompletionDate!== "Invalid date" && item.plannedCompletionDate!== "");

    if (hasNonNullPlannedCompletionDate) {
        PostSubmitAssessmenteMoloyee(params).then((response:any) => {
                if (response.code == 200) {
                    message.success(response.msg)
                    visible.value = false
                    emits("getData")
                    visible.value = false
                } else {
                    message.error(response.msg)
                }
            })
    } else {
    // 停止执行并输出提示
    message.error("请填写计划完成时间")
    }
   
}
const returnVisible = ref<boolean>(false)
const returnReason = ref<string>("")
const handleOk = ()=>{
    if(returnReason.value.replace(/\s/g, '') == ''){
        message.error('请输入退回原因')
        return
    }
    PostauditAssessment({
        assessmentId:drawerRecord.value.id,
        empname:drawerRecord.value.empname,
        returnReason:returnReason.value,
        status:"back"
    })
    .then((response:any)=>{
        if (response.code == 200) {
            message.success(response.msg)
            visible.value  = false
            returnVisible.value = false
            emits("getData")
        } else {
            message.error(response.msg)
        }
    })
}

// 计算属性，计算最高得分
const calculationMaxScore = computed(() => {
    return Object.values(personalScoreList.value).reduce((total, item) => {
        const childrenMaxScoreSum = item.children.reduce((acc, child) => acc + child.maxScore, 0);
        return total + childrenMaxScoreSum;
    }, 0);
});

// 计算属性，计算自评分
const calculationSelfRating = computed(() => {
    return Object.values(personalScoreList.value).reduce((total, item) => {
        const childrenMaxScoreSum = item.children.reduce((acc, child) => acc + child.selfRating, 0);
        return total + childrenMaxScoreSum;
    }, 0);
});
// 计算属性，部门评分
const calculationDepartmentRating = computed(() => {
    return Object.values(personalScoreList.value).reduce((total, item) => {
        const childrenMaxScoreSum = item.children.reduce((acc, child) => acc + child.departmentRating, 0);
        return total + childrenMaxScoreSum;
    }, 0);
});
// 计算属性，支部评分
const calculationBranchRating = computed(() => {
    return Object.values(personalScoreList.value).reduce((total, item) => {
        const childrenMaxScoreSum = item.children.reduce((acc, child) => acc + child.branchRating, 0);
        return total + childrenMaxScoreSum;
    }, 0);
});
// 计算属性，领导评分
const calculationSupervisorRating = computed(() => {
    return Object.values(personalScoreList.value).reduce((total, item) => {
        const childrenMaxScoreSum = item.children.reduce((acc, child) => acc + child.supervisorRating, 0);
        return total + childrenMaxScoreSum;
    }, 0);
});
// 暴露给父组件
defineExpose({
    showDrawer
})
</script>

<style  scoped>

.table-header {
    display: flex;
    width: 1235px;
    /* align-items: center; */
    /* border-top: 1px solid #f0f0f0; */
    border-left: 1px solid #f0f0f0;
}

.table-header>div {
    border-right: 1px solid #f0f0f0;
    border-bottom: 1px solid #f0f0f0;
    /* flex: 1; */
    /* height: 50px; */
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ant-input {
    border: none !important;
}

.ant-input:focus {
    border: none !important;
    box-shadow: none !important;
}

.clear-border {
    align-items: normal;
}

.clear-border div {
    border: 1px solid #d9d9d9;
    min-height: 30px;

}

.table-chidren>div {
    border-bottom: none;
    line-height: 2;
    border-right: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0;

}
</style>
